<?php
class Adhesion_model extends CI_Model {

	var $id_publication = null;
	var $id_utilisateur = null;
	var $type = null;
	var $date_maj = null;
	var $date_creation = null;
	var $statut = null;
	
	function __construct()
	{
		parent::__construct();
	}
		
	function create ()
	{
		$this->date_creation = date_db_format();
		if ( $this->id_utilisateur==null)
			$result = FALSE;
		else{
			$result = $this->db->insert('adhesion', $this);
			}			
		return $result;	
	}
	
	function get_all ()
	{
		$query = $this->db->get('adhesion');
		return $query->result();
	}
	
	function get_users()
	{
		$this->db->select('u.id_utilisateur,u.nom,u.prenom');
		$this->db->from('adhesion a');
		$this->db->where('a.id_publication',$this->id_publication);
		$this->db->where('statut',1);
		$this->db->join('utilisateur u','u.id_utilisateur=a.id_utilisateur');
		$query = $this->db->get();
		return $query->result();
	}
	
	function deja_adherant()
	{
	$query = $this->db->get_where('adhesion', array('id_utilisateur' => $this->id_utilisateur, 'id_publication' => $this->id_publication));
	return $query->result();
	}
	}?>